package com.atguigu.sort;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

//选择排序
public class SelectSort {
    public static void main(String[] args) {

//        int arr[] = new int[]{-3, 2, 1, 3, 0};
        int arr[] = new int[80000];
        for (int i=0;i<80000;i++){
            arr[i] = (int) (Math.random() * 8000000);
        }
        Date date1 = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");
        String format = simpleDateFormat.format(date1);
        System.out.println("遍历前的时间"+format);
        selectSort(arr);
        Date date2 = new Date();
        String format1 = simpleDateFormat.format(date2);
        System.out.println("遍历后的时间"+format1);
    }

    public static void selectSort(int arr[]) {

        for (int j = 0; j < arr.length - 1; j++) {
            //定义排名下标
            int min = j;
            //保存中间值
            int temp = arr[j];
            for (int i = 1 + j; i < arr.length; i++) {
                if (temp > arr[i]) {
                    temp = arr[i];
                    min = i;
                }
            }
            if (min != j) {
                arr[min] = arr[j];
                arr[j] = temp;
            }
        }
    }
}
